<template>
<div class="app-container">
    <el-form :inline="true">
        <el-form-item>
            <el-input v-model="username" placeholder="用户名" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getUser()">查询</el-button>
        </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="userList" element-loading-text="Loading" border fit highlight-current-row>
        <el-table-column align="center" label="用户名" prop="username">
        </el-table-column>
        <el-table-column align="center" label="手机号码" prop="telephone">
        </el-table-column>
        <el-table-column align="center" label="E-mail" prop="email">
        </el-table-column>
        <el-table-column align="center" label="真实姓名" prop="realname">
        </el-table-column>
        <el-table-column align="center" label="身份证号码" prop="idnumber">
        </el-table-column>
        <el-table-column align="center" label="账户余额" prop="balance">
        </el-table-column>
        <el-table-column align="center" label="收货地址" prop="address">
        </el-table-column>

        <el-table-column align="center" label="操作">
            <template slot-scope="scope">
                <router-link :to="'/user/editUser/'+scope.row.id">
                    <el-button size="mini" type="primary" icon="el-icon-edit">修改</el-button>
                </router-link>

                <el-button size="mini" type="danger" icon="el-icon-delete" @click="removeById(scope.row.id)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :total="total" :page-size="limit" :page-sizes="[5, 10, 20]" style="padding: 30px 0; text-align: center" layout="sizes, prev, pager, next, jumper, ->, total" @current-change="changeCurrentPage" @size-change="changePageSize" />
</div>
</template>

<script>
export default {
    data() {
        return {
            userList: [],
            listLoading: true,
            url: "http://localhost:8888/user/user/user/findAllUser",
            page: 1,
            limit: 5,
            total: 0,
            username: '',
            hotelLevel: ''
        }
    },
    created() {
        this.getUser();
    },
    watch: {
        username: function () {
            this.getUser()
        }
    },
    methods: {

        getUser(form) {

            this.listLoading = true
            this.axios.get(this.url, {
                params: {
                    page: this.page,
                    limit: this.limit,
                    username: this.username
                }
            }).then(res => {
                this.total = res.data.data.total;
                this.userList = res.data.data.records;
                this.listLoading = false
            })
        },
        removeById(id) {
            console.log(id)
        },
        changeCurrentPage(page) {
            this.page = page;
            this.getUser();
        },
        changePageSize(size) {
            this.limit = size;
            this.getUser();
        }
    }
}
</script>

<style>

</style>
